﻿@using Microsoft.Extensions.Configuration;
@using BootstrapBlazor.Components
@using BlazorAdmin.Models
@using BlazorAdmin.Web.Shared.Shared
@using Pangeo.Admin.Models
@using Pangeo.Admin.Web.Shared
@inject IConfiguration Configuration

<BootstrapBlazorRoot>
    <Router AppAssembly="@typeof(App).Assembly"
     AdditionalAssemblies="new[]{ typeof(BlazorAdmin.Web.Shared._Imports).Assembly, typeof(Pangeo.Admin.Web.Shared._Imports).Assembly }">
        <Found Context="routeData">
            <PageTitle>@AppInfo.CnName</PageTitle>
            <CascadingAuthenticationState>
                <CascadingValue Value=@ClientInfo Name=@nameof(ClientInfo)>
                    <CascadingValue Value=@AppInfo Name=@nameof(AppInfo)>
                        <AuthorizeView>
                            <Authorized>
                                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
                            </Authorized>
                            <NotAuthorized>
                                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLogin)" />
                            </NotAuthorized>
                        </AuthorizeView>
                    </CascadingValue>
                </CascadingValue>
            </CascadingAuthenticationState>
        </Found>
        <NotFound>
            <PageTitle>@AppInfo.CnName - Not Found(404)</PageTitle>
            <LayoutView Layout="@typeof(NotFoundLayout)" />
        </NotFound>
    </Router>
</BootstrapBlazorRoot>

@code {
    [Parameter]
    public SysInfo AppInfo { get; set; }

    [Parameter]
    public ClientInfo ClientInfo { get; set; }

    protected override void OnInitialized()
    {
        AppInfo = new SysInfo()
        {
            Name = Configuration["AppInfo:Name"],
            CnName = Configuration["AppInfo:CnName"],
            Description = Configuration["AppInfo:Description"]
        };
    }
}